<div class="people form">
<?php echo $this->Form->create('Person');?>
<fieldset>
 		<legend><?php __('Refinancing'); ?></legend>
<div class="related">
	<div class="input">
		<?php if (!empty($person_id)):?>
			<?php echo "<input type=\"hidden\" name=\"data[person_id]\" value=\"".$person_id."\"/>";?>
		<?php endif; ?>
		<?php if (!empty($building_id)):?>
			<?php echo "<input type=\"hidden\" name=\"data[building_id]\" value=\"".$building_id."\"/>";?>
		<?php endif; ?>
		<label for="ExpenditureType">Expenditure Type</label>
        <select name="data[expenditure_type]">	
		<?php
			foreach($expenses_types as $k => $v) 
			{
			echo "<option value=\"$k\">$v</option>\n";
			}
		?>
		</select>
		<label for="InstallmentQuantity">Installment quantity</label>
		<input type="text" name="data[installment_quantity]"> 							
	</div>
	<h3><?php __('Owned properties');?></h3>
	<?php if (!empty($owned_properties)):?>
	<table cellpadding = "0" cellspacing = "0">
	<tr>			
		<th><?php __(' '); ?></th>
		<th><?php __('Property Id'); ?></th>
		<th><?php __('Building Id'); ?></th>
		<th><?php __('Property Type Id'); ?></th>
		<th><?php __('Floor'); ?></th>
		<th><?php __('Flat'); ?></th>
		<th><?php __('Dividend'); ?></th>
		<th><?php __('Owner Id'); ?></th>
		<th><?php __('Owner Representative Id'); ?></th>
		<th><?php __('Tenant Id'); ?></th>
		<th><?php __('Tenant Representative Id'); ?></th>	
	</tr>
	<?php
		$i = 0;
		foreach ($owned_properties as $propertyOwned):
			$class = null;
			if ($i++ % 2 == 0) {
				$class = ' class="altrow"';
			}
		?>
		<tr<?php echo $class;?>>					
			<td><?php echo "<input type=\"checkbox\" name=\"data[".$i."][PropertyOwner][refinanced]\" value=\"".$propertyOwned['PropertyOwner']['refinanced']."\"/>";?></td>						
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][property_id]\" value=\"".$propertyOwned['PropertyOwner']['property_id']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['property_id'];?></td>
						
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][building_id]\" value=\"".$propertyOwned['PropertyOwner']['building_id']."\"/>";?>			
			<td><?php echo $propertyOwned['PropertyOwner']['building_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][property_type_id]\" value=\"".$propertyOwned['PropertyOwner']['property_type_id']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['property_type_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][floor]\" value=\"".$propertyOwned['PropertyOwner']['floor']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['floor'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][flat]\" value=\"".$propertyOwned['PropertyOwner']['flat']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['flat'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][dividend]\" value=\"".$propertyOwned['PropertyOwner']['dividend']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['dividend'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][owner_id]\" value=\"".$propertyOwned['PropertyOwner']['owner_id']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['owner_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][owner_representative_id]\" value=\"".$propertyOwned['PropertyOwner']['owner_representative_id']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['owner_representative_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][tenant_id]\" value=\"".$propertyOwned['PropertyOwner']['tenant_id']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['tenant_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyOwner][tenant_representative_id]\" value=\"".$propertyOwned['PropertyOwner']['tenant_representative_id']."\"/>";?>
			<td><?php echo $propertyOwned['PropertyOwner']['tenant_representative_id'];?></td>	
		
		</tr>
	<?php endforeach; ?>
	</table>
	<?php endif; ?>	
	<h3><?php __('Tenant Properties');?></h3>
	<?php if (!empty($tenant_properties)):?>
	<table cellpadding = "0" cellspacing = "0">
	<tr>
		<th><?php __(' '); ?></th>
		<th><?php __('Property Id'); ?></th>
		<th><?php __('Building Id'); ?></th>
		<th><?php __('Property Type Id'); ?></th>
		<th><?php __('Floor'); ?></th>
		<th><?php __('Flat'); ?></th>
		<th><?php __('Dividend'); ?></th>
		<th><?php __('Owner Id'); ?></th>
		<th><?php __('Owner Representative Id'); ?></th>
		<th><?php __('Tenant Id'); ?></th>
		<th><?php __('Tenant Representative Id'); ?></th>
		<th><?php __('End Date'); ?></th>
		<th><?php __('Created By'); ?></th>
		<th><?php __('Created'); ?></th>
		<th><?php __('Updated By'); ?></th>
		<th><?php __('Updated'); ?></th>		
	</tr>
	<?php
		$i = 0;
		foreach ($tenant_properties as $propertyTenant):
			$class = null;
			if ($i++ % 2 == 0) {
				$class = ' class="altrow"';
			}
		?>
		<tr<?php echo $class;?>>		    	
			<td><?php echo "<input type=\"checkbox\" name=\"data[".$i."][PropertyTenant][refinanced]\" value=\"".$propertyTenant['PropertyTenant']['refinanced']."\"/>";?></td>						
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][property_id]\" value=\"".$propertyTenant['PropertyTenant']['property_id']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['property_id'];?></td>
						
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][building_id]\" value=\"".$propertyTenant['PropertyTenant']['building_id']."\"/>";?>			
			<td><?php echo $propertyTenant['PropertyTenant']['building_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][property_type_id]\" value=\"".$propertyTenant['PropertyTenant']['property_type_id']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['property_type_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][floor]\" value=\"".$propertyTenant['PropertyTenant']['floor']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['floor'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][flat]\" value=\"".$propertyTenant['PropertyTenant']['flat']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['flat'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][dividend]\" value=\"".$propertyTenant['PropertyTenant']['dividend']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['dividend'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][owner_id]\" value=\"".$propertyTenant['PropertyTenant']['owner_id']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['owner_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][owner_representative_id]\" value=\"".$propertyTenant['PropertyTenant']['owner_representative_id']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['owner_representative_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][tenant_id]\" value=\"".$propertyTenant['PropertyTenant']['tenant_id']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['tenant_id'];?></td>
			
			<?php echo "<input type=\"hidden\" name=\"data[".$i."][PropertyTenant][tenant_representative_id]\" value=\"".$propertyTenant['PropertyTenant']['tenant_representative_id']."\"/>";?>
			<td><?php echo $propertyTenant['PropertyTenant']['tenant_representative_id'];?></td>	
		</tr>
	<?php endforeach; ?>
	</table>
	<?php endif; ?>
	<div class="actions">
		<ul>
			<li><?php echo $this->Html->link(__('New Property Tenant', true), array('controller' => 'properties', 'action' => 'add'));?> </li>
		</ul>
	</div>
</fieldset>
<?php echo $this->Form->end(__('Refinance', true));?>
</div>